package com.qingmi.farmer.data.repository.api;

import com.qingmi.farmer.data.model.UpdateVersion;
import com.wjjun.base.data.net.HTTPSService;
import com.wjjun.base.data.preference.UserPreference;
import com.qingmi.farmer.data.request.GetCodeReq;
import com.wjjun.basemvpvm.data.model.SimpleEntity;
import com.wjjun.basemvpvm.data.net.HttpApiManager;
import com.wjjun.basemvpvm.data.net.filter.BaseResponseFilter;
import com.wjjun.basemvpvm.data.repository.BaseApiRepository;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.MultipartBody;

/**
 * 基础模块
 * Created by 67535 on 2018/5/23.
 */
public class BasicApiRepository extends BaseApiRepository {


    private UserPreference userPreference;

    @Inject
    public BasicApiRepository(HttpApiManager httpApiManager, BaseResponseFilter filter, UserPreference userPreference) {
        super(httpApiManager, filter);
        this.userPreference = userPreference;
    }

    /**
     * 获取短信验证码
     */
    public Observable<SimpleEntity> getCode(GetCodeReq req) {
        return res2SimpleEntity(httpApiManager.getService(HTTPSService.class).getCode(req.toMap()));
    }

    /**
     * 上传图片
     */
    public Observable<List<String>> uploadImg(MultipartBody.Part req){
        return res2Entity(httpApiManager.getService(HTTPSService.class).uploadImg(req, userPreference.getToken()));
    }

    /**
     * 检查更新
     */
    public Observable<UpdateVersion> updateVersion(){
        return res2Entity(httpApiManager.getService(HTTPSService.class).updateVersion());
    }

}
